package org.totoro.bytecode.jit;


/**
 * jit 测试
 * <p>
 * 配合 jitwatch 查看重排序代码
 * <p>
 * 参考地址：https://app.yinxiang.com/shard/s45/nl/10505682/e65cbe03-6ea9-45eb-b5e4-281e80b4415a
 * https://app.yinxiang.com/shard/s45/nl/10505682/92262eaf-2200-4d62-a1c5-530d15f176fd
 * <p>
 * jvm 参数：  -XX:+UnlockDiagnosticVMOptions  -XX:+PrintAssembly -XX:+LogCompilation -XX:LogFile=jit.log
 *
 * <p>
 * <p>
 * 常见错误
 * <p>
 * Could not load hsdis-amd64.dylib; library not loadable; PrintAssembly is disabled
 * <p>
 * 需要下载 <a href='https://github.com/evolvedmicrobe/benchmarks/blob/master/hsdis-amd64.dylib'>hsdis-amd64.dylib </a> 然后移动到 jre lib 目录。
 * <p>
 * $ sudo mv hsdis-amd64.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib
 *
 * @author daocr
 * @date 2020/2/29
 */
public class JitTest {

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {

            for (int i1 = 0; i1 < 10000; i1++) {
                new Object();
            }

            long l = System.nanoTime();
            System.out.println(i + "\t" + (System.nanoTime() - l));
        }
    }
}
